﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using DataAccessLayer.Entity;
using System.Data;
namespace DataAccessLayer.Adapter
{
    public class QuanHuyenAdapter
    {
        clsKetNoiCSDL kn = new clsKetNoiCSDL();
        DataTable dt;
        public DataTable LoadQuanHuyen()
        {
            return dt = kn.LoadDL("tbQuanHuyen_SelectAll");
        }
        public DataTable LoadTenQuanHuyen(clsQuan_Huyen clsQuanHuyen)
        {
            string sql = "tbQuanHuyen_SelectTenQuan";
            int Npa = 1;
            string []name=new string[Npa];
            object[] value=new object[Npa];
            name[0] = "@MaTinh"; value[0] = clsQuanHuyen.MaTinhThanh;
            dt = kn.LoadDL(sql, name, value, Npa);
            return dt;
        }
        public DataTable LoadTenQuan(clsQuan_Huyen clsQuanHuyen)
        {
            string sql = "tbQuanHuyenLoadTenQuan";
            int N = 1;
            string[] name = new string[N];
            object[]value=new object[N];
            name[0] = "@MaTinh"; value[0] = clsQuanHuyen.MaTinhThanh;
            return kn.LoadDL(sql,name,value,N);
        }
        public void ThemQuanHuyen(clsQuan_Huyen clsQuan)
        {
            int Npa = 4;
            string sql = "tbQuanHuyenThem";
            string []name =new string[Npa];
            object[] value=new object[Npa];
            name[0] = "@MaHuyen"; value[0] = clsQuan.MaHuyen;
            name[1] = "@TenHuyen"; value[1] = clsQuan.TenHuyen;
            name[2] = "@MaTinh"; value[2] = clsQuan.MaTinhThanh;
            name[3] = "@Active"; value[3] = clsQuan.Active;
            kn.UpdateDL(sql, name, value, Npa);
        }
        public void SuaQuanHuyen(clsQuan_Huyen clsQuan)
        {
            int Npa = 3;
            string sql = "tbQuanHuyenSua";
            string[] name = new string[Npa];
            object[] value = new object[Npa];
            name[0] = "@MaHuyen"; value[0] = clsQuan.MaHuyen;
            name[1] = "@TenHuyen"; value[1] = clsQuan.TenHuyen;
            name[2] = "@MaTinh"; value[2] = clsQuan.MaTinhThanh;
            //name[3] = "@Active"; value[3] = clsQuan.Active;
            kn.UpdateDL(sql, name, value, Npa);
        }
        public void XoaQuanHuyen(clsQuan_Huyen clsQuan)
        {
            int Npa = 1;
            string sql = "tbQuanHuyenXoa";
            string[] name = new string[Npa];
            object[] value = new object[Npa];
            name[0] = "@MaHuyen"; value[0] = clsQuan.MaHuyen;
            kn.UpdateDL(sql,name,value,Npa);
        }
        object kq;
        public object KiemTraMa(clsQuan_Huyen clsQuanHuyen)
        {
            string sql = "tbQuanHuyen_KiemTraMa";
            int Npa = 2;
            string []name=new string[Npa];
            object []value=new object[Npa];
            name[0] = "@MaQuanHuyen"; value[0] = clsQuanHuyen.MaHuyen;
            name[1] = "@MaTinh"; value[1] = clsQuanHuyen.MaTinhThanh;
            kq = kn.KTTrungMa(sql,name,value,Npa);
            return kq;
        }
    }
}
